package com.check.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.check.dao.WorkRoleDao;
import com.check.pojo.PageObject;
import com.check.pojo.WorkRole;
import com.check.service.WorkRoleService;

@Service("workRoleService")
public class WorkRoleServiceImpl  implements WorkRoleService{

	@Autowired
	@Qualifier("workRoleDao")
	private WorkRoleDao workRoleDao;
	
	
	public List<WorkRole> findAllWorkRole(PageObject pageObject) {
		Map<String,Integer> map = new HashMap<String,Integer>();
		map.put("startNum", pageObject.getStartNum());
		map.put("endNum", pageObject.getEndNum());
		return workRoleDao.findAllWorkRole(map);
	}

	public WorkRole findByWorkRoleID(String w_id) {
		WorkRole workRole=null;
		try {
			workRole=workRoleDao.findWorkRoleById(w_id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return workRole;
	}

	public List<WorkRole> findAllWorkRoleByType(String w_type){
		return workRoleDao.findAllWorkRoleByType(w_type);	
	}
	
	public boolean insertWorkRole(WorkRole workRole) {
		boolean flag=false;
		try {
			workRoleDao.insertWorkRole(workRole);
			flag=true;
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			flag=false;
		}
		return flag;
	}

	public boolean updateWorkRole(WorkRole workRole) {
		boolean flag=false;
		try {
			workRoleDao.updateWorkRole(workRole);
			flag=true;
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			flag=false;
		}
		return flag;
	}

	public boolean deleteWorkRole(String w_id) {
		boolean flag=false;
		try {
			workRoleDao.deleteWorkRole(w_id);
			workRoleDao.deleteWorkRoleCom(w_id);
			flag=true;
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			flag=false;
		}
		return flag;
	}

	public int findWorkRoleCount() {
		return workRoleDao.findWorkRoleCount();
	}

}
